package lt.hsu.security;


import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;

/**
 * @author Josh Cummings
 */
@EnableWebSecurity
@Configuration
public class WebSecurityConfig  {

//    private final JWSAlgorithm jwsAlgorithm = JWSAlgorithm.RS256;
//    private final JWEAlgorithm jweAlgorithm = JWEAlgorithm.RSA_OAEP_256;
//    private final EncryptionMethod encryptionMethod = EncryptionMethod.A256GCM;
//
//    @Value("${spring.security.oauth2.resourceserver.jwt.jwk-set-uri}")
//    URL jwkSetUri;
//
//    @Value("${sample.jwe-key-value}")
//    RSAPrivateKey key;
//
//    @Bean
//    public PasswordEncoder passwordEncoder() {
//        return new BCryptPasswordEncoder();
//    }
//
//
//    @Bean
//    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
////        http
////                .authorizeHttpRequests(authorize -> authorize
////                        .requestMatchers("/messages/**").access(hasScope("message:read"))
////                        .anyRequest().authenticated()
////                )
////                .oauth2ResourceServer(oauth2 -> oauth2
////                        .jwt(jwt -> jwt
//////                                .jwtAuthenticationConverter(myConverter())
////                        )
////                );
//        return http.build();
//    }
//
//    @Bean
//    JwtDecoder jwtDecoder() {
//        return new NimbusJwtDecoder(jwtProcessor());
//    }
//
//    private JWTProcessor<SecurityContext> jwtProcessor() {
//        JWKSource<SecurityContext> jwsJwkSource = new RemoteJWKSet<>(this.jwkSetUri);
//        JWSKeySelector<SecurityContext> jwsKeySelector =
//                new JWSVerificationKeySelector<>(this.jwsAlgorithm, jwsJwkSource);
//
//        JWKSource<SecurityContext> jweJwkSource = new ImmutableJWKSet<>(new JWKSet(rsaKey()));
//        JWEKeySelector<SecurityContext> jweKeySelector =
//                new JWEDecryptionKeySelector<>(this.jweAlgorithm, this.encryptionMethod, jweJwkSource);
//
//        ConfigurableJWTProcessor<SecurityContext> jwtProcessor = new DefaultJWTProcessor<>();
//        jwtProcessor.setJWSKeySelector(jwsKeySelector);
//        jwtProcessor.setJWEKeySelector(jweKeySelector);
//
//        return jwtProcessor;
//    }
//
//    private RSAKey rsaKey() {
//        RSAPrivateCrtKey crtKey = (RSAPrivateCrtKey) this.key;
//        Base64URL n = Base64URL.encode(crtKey.getModulus());
//        Base64URL e = Base64URL.encode(crtKey.getPublicExponent());
//        return new RSAKey.Builder(n, e)
//                .privateKey(this.key)
//                .keyUse(KeyUse.ENCRYPTION)
//                .build();
//    }
}
